package com.ywgt.system.service.impl;

import com.ywgt.system.pojo.Menu;
import com.ywgt.system.mapper.MenuMapper;
import com.ywgt.system.pojo.User;
import com.ywgt.system.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ywgt.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author yiping
 * @since 2021-01-18
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {

    @Autowired
    private UserService userService;

    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<Menu> getMenuByUsername(String username) {
        User user = userService.getUserByUsername(username);
        if (user==null){
            throw new UsernameNotFoundException("用户不存在");
        }
       return baseMapper.getMenus(user.getId());
    }

    @Override
    public List<Menu> getMenuByRole() {
       return menuMapper.getMenuByRole();
    }

    @Override
    public List<Menu> getMenuTree() {
        return menuMapper.getMenuTree();
    }

    @Override
    public List<Menu> getMenuByRoleId(Integer id) {
      return   menuMapper.getMenuByRoleId(id);
    }
}
